//
//  HYOUStrategyView.m
//  BestGift
//
//  Created by 温晓宇 on 15/12/30.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "HYOUStrategyView.h"
#import "HYOUStrategyHeadView.h"
#import "HYOUStrategyCell.h"
#import "HYOUStrategyCollectionModel.h"
@interface HYOUStrategyView ()<UITableViewDataSource, UITableViewDelegate,HYOUStrategyCellDelegate,HYOUStrategyHeadViewDelegate>

@property(nonatomic, retain)HYOUBaseTableView *myTableView;
@property(nonatomic, retain)HYOUStrategyHeadView *head;

@end

@implementation HYOUStrategyView
-(void)dealloc{
    [_nameGroupsArray release];
    [_allArray release];
    [_myTableView release];
    [_categoryArray release];
    [_targetArray release];
    [_styleArray release];
    [_occasionArray release];
    [super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews{
    self.myTableView = [[HYOUBaseTableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
//    self.myTableView.backgroundColor = [UIColor whiteColor];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self addSubview:self.myTableView];
    
    self.head = [[HYOUStrategyHeadView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 140)];
//    self.head.backgroundColor = [UIColor whiteColor];
    self.myTableView.tableHeaderView = self.head;
    self.head.delegate = self;
    [_myTableView release];
    [_head release];
    
    [self.myTableView registerClass:[HYOUStrategyCell class] forCellReuseIdentifier:@"cell"];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.nameGroupsArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        if (indexPath.row == 0) {
//            if (self.categoryArray != 0) {
                HYOUStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            cell.delegate = self;
                cell.name = self.nameGroupsArray[0];
                cell.allArray = self.categoryArray;
                return cell;
//            }
        }
    if (indexPath.row == 1) {
//        if (self.styleArray.count != 0) {
            HYOUStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            cell.name = self.nameGroupsArray[1];
        cell.delegate = self;
            cell.allArray = self.targetArray;
            return cell;
//        }
    }
    if (indexPath.row == 2) {
        HYOUStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.name = self.nameGroupsArray[2];
        cell.delegate = self;
        cell.allArray = self.styleArray;
        return cell;
    }else{
        HYOUStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.name = self.nameGroupsArray[3];
        cell.allArray = self.occasionArray;
        cell.delegate = self;
        return cell;
    }
    
    
//            HYOUStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//            return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 530;
    }
    if (indexPath.row == 3) {
        return 420;
    }
    return 300;
}
-(void)showSeeMore{
    [self.delegate showSeeMore];
}
-(void)showDetail:(NSString *)url{
    [self.delegate showDetail:url];
}
-(void)showTopic:(NSString *)url{
    [self.delegate showTopic:url];
}
-(void)setNameGroupsArray:(NSMutableArray *)nameGroupsArray{
    if (_nameGroupsArray != nameGroupsArray) {
        [_nameGroupsArray release];
        _nameGroupsArray = [nameGroupsArray retain];
    }
    [self.myTableView reloadData];
}
-(void)setAllArray:(NSMutableArray *)allArray{
    if (_allArray != allArray) {
        [_allArray release];
        _allArray = [allArray retain];
    }
    self.head.allArray = self.allArray;
}

-(void)setCategoryArray:(NSMutableArray *)categoryArray{
    if (_categoryArray != categoryArray) {
        [_categoryArray release];
        _categoryArray = [categoryArray retain];
    }
    [self.myTableView reloadData];
}
-(void)setTargetArray:(NSMutableArray *)targetArray{
    if (_targetArray != targetArray) {
        [_targetArray release];
        _targetArray = [targetArray retain];
    }
    [self.myTableView reloadData];
}
-(void)setStyleArray:(NSMutableArray *)styleArray{
    if (_styleArray != styleArray) {
        [_styleArray release];
        _styleArray = [styleArray retain];
    }
    [self.myTableView reloadData];
}
-(void)setOccasionArray:(NSMutableArray *)occasionArray{
    if (_occasionArray != occasionArray) {
        [_occasionArray release];
        _occasionArray = [occasionArray retain];
    }
    [self.myTableView reloadData];
}



@end
